<?php

namespace App\Models\Biz;

use Illuminate\Database\Eloquent\Model;
use Laracasts\Presenter\PresentableTrait;

class Borrow extends Model
{
    use PresentableTrait;

    protected $table = 'biz_borrows';

    protected $presenter = 'App\Http\Presenters\BorrowPresenter';

    protected $guarded = array();

    public $timestamps = false;

    /*
        0:未还/1:已还
     */
    const BORROW_STATUS_UNRETURN  = 0;
    const BORROW_STATUS_RETURNED  = 1;
    

    public function book()
    {
        return $this->belongsTo('App\Models\Mgt\Book', 'bookid');
    }


    public function user()
    {
        return $this->belongsTo('App\Models\Mgt\User', 'uid', 'id');
    }


    public function scopeUnreturn($q)
    {
        return $q->where('status', self::BORROW_STATUS_UNRETURN);
    }

    public function scopeReturned($q)
    {
        return $q->where('status', self::BORROW_STATUS_RETURNED);
    }

}